/*
#Copyright (c) 2013, Philippe Bordron <philippe.bordron@gmail.com>
#
# This file is part of SIPPER.
#
# DCC is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU LESSER GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# along with SIPPER.  If not, see <http://www.gnu.org/licenses/>
*/
package combi.wip.sipper.modeling.integratedModel;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import combi.wip.sipper.modeling.Protein;
import combi.wip.sipper.modeling.genomes.Gene;
import combi.wip.sipper.modeling.genomes.Genome;
import combi.wip.sipper.modeling.metabolicNetworks.MetabolicNetworkWithEnzymes;
import combi.wip.sipper.modeling.reactions.Reaction;

public class Catalyze<G extends Gene<E>,R extends Reaction<C>, C, E extends Protein> {

	protected Genome<Gene<E>,E> genome;
	protected MetabolicNetworkWithEnzymes<C, Reaction<C>,E> meta;
	protected Map<Reaction<C>, Collection<Gene<E>>> reactionToGenes;
	//Map<String, Set<String>> geneToReactions;

	public Catalyze(Genome<Gene<E>,E> genome, MetabolicNetworkWithEnzymes<C, Reaction<C>,E> meta)
	{
		this.genome = genome;
		this.meta = meta;
		genereCatalyze();
	}

	private void genereCatalyze()
	{
		reactionToGenes = new HashMap<Reaction<C>, Collection<Gene<E>>>();
		for(Reaction<C> r : meta.getReactionSet())
		{
			Set<Gene<E>> set = new HashSet<Gene<E>>();
			//System.err.println(r +" : " + meta.getEnzyme(r));
			for (Protein e : meta.getEnzymes(r))
			{
				for (Protein p : e.getDeepComponents())
				{
					set.addAll(genome.getGenes(p));
				}
			}
			if (!set.isEmpty())
			{
				reactionToGenes.put(r,set);
			}
		}
	}

	public Map<Reaction<C>, Collection<Gene<E>>> getReactionToGenes()
	{
		return reactionToGenes;
	}


	public String toString()
	{
		return reactionToGenes.toString();
	}
}
